package com.film.controller.movie;

import com.alibaba.fastjson.JSONObject;
import com.film.jwt.JwtUtil;
import com.film.service.impl.movie.FetchMoviesServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;

//拉取所有电影
@RestController
public class FetchMoviesController {
    @Autowired
    private FetchMoviesServiceImpl fetchMoviesService;

    @GetMapping("/movie/fetch/{token}")
    public JSONObject fetchMovies(@PathVariable String token) throws SQLException {
        if (!JwtUtil.JwtVerify(token)) {
            JSONObject resp = new JSONObject();
            resp.put("error_message", "jwt验证错误");
            return resp;
        } else {
            return fetchMoviesService.fetchMovies();
        }
    }
}
